package com.um.springboot.starter.exception;

import com.um.springboot.starter.code.CommonCode;
import com.um.springboot.starter.utils.EnumUtil;
import lombok.Getter;

/**
 * 业务异常
 * @author renjunwei
 * @date 2020/9/19 09:37
 */
@Getter
public class ServiceException extends RuntimeException{

    Integer errCode;
    String msg;
    Object data;

    public ServiceException(Integer errCode){
        this.errCode = errCode;
        this.msg = null;
    }

    public ServiceException(Integer errCode,String msg){
        super(msg);
        this.errCode = errCode;
        this.msg = msg;
    }

    public ServiceException(String msg){
        super(msg);
        this.errCode = CommonCode.Failed.getCode();
        this.msg = msg;
    }

    public <T extends EnumUtil.ErrorEnum> ServiceException(T error){
        super(error.getMsg());
        this.errCode = error.getCode();
        this.msg = error.getMsg();
    }

    public <T extends EnumUtil.ErrorEnum> ServiceException(T error, Object data){
        super(error.getMsg());
        this.errCode = error.getCode();
        this.msg = error.getMsg();
        this.data = data;
    }

}
